import { Component, OnInit } from '@angular/core';
import { Observable } from "rxjs/Observable";
import { BladeContainerBase } from "../../../../shared/blade/blade-container-base";
import { BladeData } from "../../../../shared/blade/blade-data";
import { Blade } from "../../../../shared/blade/blade.model";
import { Command } from "../../../../shared/toolbar.service";
import { Tag } from "../../../../entity/tag.model";
import { DialogResult } from "../../../../shared/dialog.service";
import { TagService } from "../../../../service/tag.service";
import { TagEditComponent } from '../tag-edit/tag-edit.component';
@Component({
  selector: 'app-tag-details',
  templateUrl: './tag-details.component.html',
  styleUrls: ['./tag-details.component.css']
})
export class TagDetailsComponent extends BladeContainerBase<Tag>{

  constructor() {
    super();
  }

  ngOnInit() {
    this.commands = [
      new Command("edit", "编辑", "fa fa-edit", "setofkey:update", blade => this.exeEdit(blade), blade => this.canExeEdit(blade)),
      new Command("delete", "删除", "fa fa-trash-o", "setofkey:delete", blade => this.exeDelete(blade), blade => this.canDelete(blade))
    ];
    super.ngOnInit();
  }

  exeEdit(blend: Blade): void {
    if (this.currentEntity != undefined) {

      let data: BladeData = new BladeData();
      data.id = "tagEdit";
      data.title = this.currentEntity.tagName;
      let editKeyBlade = this.bladeService.createBlade(TagEditComponent, data, false, this.currentEntity);
      this.currentBlade.bladeService.showBlade(editKeyBlade, this.currentBlade);
    }
  }
  canExeEdit(blend?: Blade): boolean {
    return this.currentEntity != null;
  }
  exeDelete(blend: Blade): void {
    let selectedKeys = this.currentEntity;
    this.dialogService
      .showConfirmationDialog("确认删除", "是否要删除选中项？")
      .subscribe(dialogResult => {
        /* if (dialogResult == DialogResult.Ok) {
           this.currentBlade.bladeData.isLoading = true;
           this.turbastatusService.batchDelete(selectedKeys.map(o => o.statusId))
             .then(res => {
               if (res) {
                 this.refresh(undefined);
               }
             })
             .catch(error => this.bladeData.error = error)
             .then(res => this.bladeData.isLoading = false);
         }*/
      })
  }

  canDelete(blend?: Blade): boolean {
    return true;
  }
  showTagEditBlade() {
    if (this.currentEntity != undefined||this.bladeService.findBlade("tagEdit") == undefined) {
      let data: BladeData = new BladeData();
      data.id = "tagEdit";
      data.title = this.currentEntity.tagName;
      let editKeyBlade = this.bladeService.createBlade(TagEditComponent, data, false, this.currentEntity);
      this.currentBlade.bladeService.showBlade(editKeyBlade, this.currentBlade);
    }
  }
  onSeletedChange() {
      this.showTagEditBlade();
   }
}



// WEBPACK FOOTER //
// ./src/app/module/basic/tag/tag-details/tag-details.component.ts